package com.yln.watcher.client;

import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.data.Stat;

public class BecomeMasterCallback implements AsyncCallback.Create2Callback {
    @Override
    public void processResult(int rc, String path, Object ctx, String name, Stat stat) {
        ZkClient client = (ZkClient) ctx;
        KeeperException.Code code = KeeperException.Code.get(rc);
        switch (code) {
            case OK:
                client.becomeMaster();
                break;
            case NODEEXISTS:
                client.becomeWorker();
                break;
            default:
                ;

        }
    }
}
